<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.topisv.tms.entity.GoodsShelf" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%@ page import="com.topisv.tms.entity.PipeStock" %>
<%@ page import="com.topisv.tms.entity.StoragePipe" %>
<%@ page import="com.topisv.tms.entity.PipeStockDetail" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<%
	GoodsShelf goodsShelf = (GoodsShelf)request.getAttribute("goodsShelf");
	Map pipeStocks = (Map)request.getAttribute("pipeStocks");
	StoragePipe storagePipe = (StoragePipe)request.getAttribute("storagePipe");
	String shelf_code = (String)request.getAttribute("shelf_code");
	String pipe_code = storagePipe.getPipe_code();
 %>
<html>
<head>
	<title>通道管理</title>
	
	<script>
		
		function copyPipe() {
			var shelf_num = $("#shelf_num").val();
			var shelf_type = $("#shelf_type").val();
			$.ajax({
				type : 'post',
				url : '${ctx}/v2/storage/addPipe',
				data : 'storagePartition_id=' + sp_id  + '&shelf_num=' + shelf_num + '&shelf_type=' + shelf_type,
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						alert("创建成功");
					} else if (data.status == "0") {
						//alert("创建失败！");
					}
				},
				error : function() {
				}
			});
		}
		var stock_code = ""
		function createStockDetail(stockCode)
		{
			stock_code = stockCode;
			$("#detail_num").val("");
		}
		
		function addStockDetail() {
			var detail_num = $("#detail_num").val();
			$.ajax({
				type : 'post',
				url : '${ctx}/v2/storage/stockDetail',
				data : 'stock_code=' + stock_code + '&detail_num=' + detail_num,
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						alert("创建成功");
					} else if (data.status == "0") {
						//alert("创建失败！");
					}
				},
				error : function() {
				}
			});
		}
	</script>
</head>

<body>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th colspan="${goodsShelf.colsnum}">
					<a href="${ctx}/v2/storage/storagePartition/${storagePipe.partition_code}" role="button" onclick="" class="btn" data-toggle="modal">返回</a>
					当前分区：${storagePipe.partition_code} 
					当前通道：${storagePipe.pipe_name} 
					货架类型：${goodsShelf.shelf_name} 
					当前货架：${shelf_code} 
					<a href="${ctx}/v2/storage/storagePipe/${storagePipe.id}/${shelf_code -1}" role="button" onclick="" class="btn" data-toggle="modal">上一个</a>
					<a href="${ctx}/v2/storage/storagePipe/${storagePipe.id}/${shelf_code +1}" role="button" onclick="" class="btn" data-toggle="modal">下一个</a>
				</th>
			</tr>
		</thead>
		<tbody>
			<%
				int rowsnum = goodsShelf.getRowsnum();
				int colsnum = goodsShelf.getColsnum();
				if(pipeStocks != null)
				{
				for(int i=1; i<= rowsnum; i++)
				{
			 %>
				<tr>
					<%
						for(int j=1; j<= colsnum; j++)
						{
							PipeStock pipeStock = (PipeStock)pipeStocks.get(pipe_code + "-" + shelf_code + i + j);
							if(pipeStock != null)
							{
					 %>
								<td height="60px">
									<%=pipeStock.getStock_code() %><br/>
									所属客户：<%=pipeStock.getCustomer_code() %><br/>
									<%
										if("0".equals(pipeStock.getStock_status()) && "0".equals(pipeStock.getStock_type()))
										{
											String stock_code = pipeStock.getStock_code();
									 %>
									 	<a href="#stock_detail" 
									 			role="button" onclick="createStockDetail('<%=stock_code %>');" class="btn" data-toggle="modal">拆分</a>
									 <%
									 	}
									 	else
									 	{
									  %>
									  拆分个数：<%=pipeStock.getPipeStockDetailList().size() %>
									  <%
									  	}
									   %>
								</td>
					<%
							}
						}
					 %>
				</tr>
			<%
				}
				}
			 %>
		</tbody>
	</table>
	<div style="display: none; width: 1000" class="modal hide fade"
			tabindex="-1" role="dialog" aria-labelledby="myModalLabel1"
			aria-hidden="true" id="stock_detail">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">
					×
				</button>
				<h3 id="myModalLabel11">
					拆分库位
				</h3>
			</div>
			<div class="modal-body">
				<table class="table table-striped table-bordered table-condensed"
					id="expressStatus_tab1">
					<tr>
						<td>
							拆分个数
						</td>
						<td>
							<input type="text" id="detail_num" name="detail_num"  value="" />
						</td>
					</tr>
				</table>
			</div>
			<div class="modal-footer">
				<button class="btn" onclick="addStockDetail();" data-dismiss="modal" aria-hidden="true">
					确定
				</button>
			</div>
		</div>
</body>
</html>
